package com.gewu.pm.ui.fragment.terminal;

import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gewu.pm.R;
import com.gewu.pm.app.AppFragment;
import com.gewu.pm.ui.adapter.sales.VisitRecordAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 终端详情 - 拜访记录 Fragment
 */
public final class VisitRecordFragment extends AppFragment<com.gewu.pm.app.AppActivity>
        implements com.hjq.base.BaseAdapter.OnItemClickListener {

    private TextView mStartDateView;
    private TextView mEndDateView;
    private RecyclerView mRecyclerView;
    private VisitRecordAdapter mAdapter;//注意：用的拜访记录适配器，部分UI不同，需要修改

    public static VisitRecordFragment newInstance() {
        return new VisitRecordFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.terminal_visit_record_fragment;
    }

    @Override
    protected void initView() {
        mStartDateView = findViewById(R.id.tv_start_date);
        mEndDateView = findViewById(R.id.tv_end_date);
        mRecyclerView = findViewById(R.id.rv_visit_record);

        // 设置 RecyclerView
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mAdapter = new VisitRecordAdapter(getContext());
        
        // 必须在 setAdapter 之前设置监听器
        mAdapter.setOnItemClickListener(this);
        mRecyclerView.setAdapter(mAdapter);

        // 点击日期
        mStartDateView.setOnClickListener(v -> {
            // TODO: 打开日期选择器
            toast("选择开始日期");
        });

        mEndDateView.setOnClickListener(v -> {
            // TODO: 打开日期选择器
            toast("选择结束日期");
        });
    }

    @Override
    protected void initData() {
        // TODO: 加载拜访记录数据
        List<String> testData = new ArrayList<>();
        testData.add("陈宏伟");
        testData.add("陈宏伟");
        mAdapter.setData(testData);
    }

    @Override
    public void onItemClick(androidx.recyclerview.widget.RecyclerView recyclerView, android.view.View itemView, int position) {
        String visitorName = mAdapter.getItem(position);
        toast("点击拜访记录：拜访人-" + visitorName);
        // TODO: 打开拜访记录详情
    }
}

